<?php
/**
 * @Author: Marte
 * @Date:   2017-08-22 18:51:54
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-08-23 21:27:15
 */

header('Content-Type:text/html;charset=utf-8');
require 'data/config_connect.php';
if(isset($_GET['wk']))
{
    $bookname=$_GET['wk'];
    $note="INSERT INTO search ( search, time)
    VALUES ('$bookname', now())";
    $_mysql->query($note);

}else{
    exit;
}

//首先当做书名来查找
$_sql='select * from books where bookname="'.$bookname.'"';

$_sql1='select * from books where bookauthor="'.$bookname.'"';
$_result1=$_mysql->query($_sql);
// $num1=mysqli_affected_rows($_mysql);





?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>全站搜索</title>
    <link rel="stylesheet" type="text/css" href="css/search.css">
    <script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>
    <script src="js/search_index_.js"></script>
</head>
<body>
      <div class="header">
        <div class="header_main">
            <div class="header_left">
             <?php

            session_start();

            if(!isset($_GET["action"])||$_GET['action']!='1')
            {
                echo '<span>欢迎您来到墨悦轩！请<a href="dl.php" title="">登录</a>或<a href="zc.php" title="">免费注册</a></span>';
                  // unset($_SESSION['username']);
            }else if($_GET['action']=='1')
            {
                echo '<span>欢迎<a href="person.php">'.$_SESSION['username'].'</a>来到墨悦轩！<a href="data/user/logout.php?exit=1" >退出</a></span>';

            }

            ?>





            </div>
            <div class="header_right">
                <a class="header_right_books" href="allbooks.php" title="">墨轩书城</a>
                <a class="header_right_me" href="mybookrack.php" title="">我的书架</a>
                <a class="header_right_free" href="#" title="">免费小说</a>
                <a class="header_right_month" href="author_register.php" title="">作者专区</a>
                <a class="header_right_last" href="person.php" title="">个人中心</a>
            </div>
        </div>
    </div>

      <!-- search -->
    <div id="search">
        <div class="logo">
                <img src="images/logo1.png" alt="">
        </div>
        <div class="search_main">




            <div class="search_main_box">
                <input class="input" type="text" name="" value="请输入关键字">
            </div>

                <input type="submit" class="search_main_box_search" name="submit" value="搜&nbsp;索" />


        <p class="hot_search">热搜： <a href="#" title="">至尊重生</a> <a href="#" title="">透视之眼</a> <a href="#" title="">神医小农名</a>
        </p>
        </div>

        <div class="search_right">

            <div class="search_right_box">

                    <a href="mybookrack.php" title="书架">俺的书架</a>
            </div>
        </div>
    </div>
    <!-- nav -->
    <div class="nav">
        <div class="nav_main" id="bar">
            <div id="navbar">
                <div class="one">

                </div>
                <div class="two">

                </div>
            </div>
            <ul>
                <li><a href="index.php" title="">首页</a></li>
                <li><a href="allbooks.php" title="">全部作品</a></li>
                <li><a href="#" title="">完本</a></li>
                <li><a href="#" title="">排行榜</a></li>
                <li><a href="author_register.php" title="">作者专区</a></li>
                 <li><a href="person.php?change=2" title="">充值</a></li>
                     <div class="clear">

    </div>
            </ul>
        </div>
    </div>

    <div class="search">
            <div class="search_left">
                <p class="search_title"><a class="all" href="" title="">全部</a><a href="" class="total" title="">共有条相关作品</a></p>
                <?php
                if($_assoc=$_result1->fetch_assoc())
                {



                 // else
                ?>
                    <ul>
                    <li>
                        <div class="li_left">
                        <img src="<?php echo $_assoc['picpath'];?>" alt="">
                        </div>
                        <div class="li_center">
                        <span class="info_2"><?php echo $_assoc['bookname'];?></span>
                            <p class="info_1"><a class="author" href="" title=""><?php echo $_assoc['bookauthor'];?></a>|<a href="" title="">
<?php
                    $_p=$_assoc['typeid'];
                    switch($_p)
                    {
                                    case 1:echo "玄幻" ;break;
                                    case 2:echo "奇幻";break;
                                    case 3:echo "武侠";break;
                                    case 4:echo "仙侠";break;
                                    case 5:echo "都市";break;
                                    case 6:echo "现实";break;
                                    case 7:echo "历史";break;
                                    case 8:echo "军事";break;
                                    case 9:echo "校园";break;
                                    case 10:echo "游戏";break;
                                    case 11:echo "言情";break;
                                    case 12:echo "灵异";break;
                                    case 13:echo "N次元";break;
                    }
                ?>
                            </a>|<a href="" title="">
                                <?php
                                $_i=$_assoc['isend'];
                                switch($_i)
                                {
                                    case 1:echo "完结";break;
                                    case 0:echo "连载中";break;

                                }
                                     ?>

                            </a> </p>
                            <p class="info_3"><?php echo $_assoc['descripation'];?></p>
                            <p class="info_4"><a href="" title="">最近更新 ：第 1034章 美女</a><a href="" class="aa" title="">2017-34-23</a></p>
                        </div>
                        <div class="li_right">
                          <span class="grade"><?php echo $_assoc['grade'];?></span>
                          <span class="hit"><?php echo $_assoc['allhits'];?>万点击</span>
                          <p><a href="bookinfo.php?id=<?php echo $_assoc['bookid'];?>" class="top" title="">书籍详情</a><a href="bookinfo.php?id=<?php echo $_assoc['bookid'];?>" title="">立即阅读</a></p>
                        </div>
                    </li>
                </ul>
                <?php


                }
                ?>
                <?php
                if( $_result2=$_mysql->query($_sql1))
               {


                while( $_ssoc=$_result2->fetch_assoc())
                {



                ?>
                 <ul>
                    <li>
                        <div class="li_left">
                        <img src="<?php echo $_ssoc['picpath'];?>" alt="">
                        </div>
                        <div class="li_center">
                        <span class="info_2"><?php echo $_ssoc['bookname'];?></span>
                            <p class="info_1"><a class="author" href="" title=""><?php echo $_ssoc['bookauthor'];?></a>|<a href="" title="">
<?php
                    $_p=$_ssoc['typeid'];
                    switch($_p)
                    {
                                    case 1:echo "玄幻" ;break;
                                    case 2:echo "奇幻";break;
                                    case 3:echo "武侠";break;
                                    case 4:echo "仙侠";break;
                                    case 5:echo "都市";break;
                                    case 6:echo "现实";break;
                                    case 7:echo "历史";break;
                                    case 8:echo "军事";break;
                                    case 9:echo "校园";break;
                                    case 10:echo "游戏";break;
                                    case 11:echo "言情";break;
                                    case 12:echo "灵异";break;
                                    case 13:echo "N次元";break;
                    }
                ?>
                            </a>|<a href="" title="">
                                <?php
                                $_i=$_ssoc['isend'];
                                switch($_i)
                                {
                                    case 1:echo "完结";break;
                                    case 0:echo "连载中";break;

                                }
                                     ?>

                            </a> </p>
                            <p class="info_3"><?php echo $_ssoc['descripation'];?></p>
                            <p class="info_4"><a href="" title="">最近更新 ：第 1034章 美女</a><a href="" class="aa" title="">2017-34-23</a></p>
                        </div>
                        <div class="li_right">
                          <span class="grade"><?php echo $_ssoc['grade'];?></span>
                          <span class="hit"><?php echo $_ssoc['allhits'];?>万点击</span>
                          <p><a href="bookinfo.php?id=<?php echo $_ssoc['bookid'];?>" class="top" title="">书籍详情</a><a href="bookinfo.php?id=<?php echo $_ssoc['bookid'];?>" title="">立即阅读</a></p>
                        </div>
                        <div class="clear">

                        </div>
                    </li>
                     <div class="clear">

                        </div>
                </ul>
                <?php
            }
                    }

                    //  if(count($assoc=$_result1->fetch_assoc())==0&&)
                    // {
                    //       echo "<span  style='display:block;font-size:16px;color:#ccc;height:20px;line-height:20px;width:100%;text-align:center;margin-top:300px;'>非常抱歉，没有找到您想要的结果！</span>";

                    // }

                ?>

            </div>
            <div class="search_right1">
                <span class="other">其他人还搜过</span>
                <ul>

                <?php

$count=0;
$flag=false;

                $pp='select search from search ';
                $_p=$_mysql->query($pp);
                while($m=$_p->fetch_assoc())
                {
                    $con=$m['search'];
                    $sl='select picpath,bookname,bookauthor,bookid from books where bookname="'.$con.'"';
                    if($_q=$_mysql->query($sl)){
                        $_n=$_q->fetch_assoc();

                        $arr[] =$_n['bookname'];
                        if($count>=3)
                        {
                            $flag=true;
                        }
                        $count++;
                    }
                    if($flag)
                    {
                        break;
                    }
                }

                ?>
                <?php
                    for($i=0;$i<4;$i++)
                    {
                        $child=$arr[$i];
                        $ll='select picpath,bookname,bookid,bookauthor from books where bookname="'.$child.'"';
                        $_kk=$_mysql->query($ll);
                        $_gg=$_kk->fetch_assoc();
                ?>
                    <li>
                        <img src="<?php echo $_gg['picpath'];?>" alt="">
                        <div class="shar">
                        <span class="share share1"><?php echo $_gg['bookname'];?></span>
                        <span class="share share2"><?php echo $_gg['bookauthor'];?></span>
                        <span class="share share3">70%人搜过</span>
                        <a href="" title="">立即阅读</a>
                        </div>

                    </li>
                    <?php
                            }
                    ?>

                </ul>
            </div>
            <div class="z">

            </div>
            <div class="clear">

                        </div>

</div>
<div class="clear">

                        </div>
<?php
                    include 'include/zhuce.footer.inc.php';
            ?>
<script>
    $('.search_main_box_search').click(function()
    {

        var name=$('.input').val();
        location.href = "search.php?wk="+name;
    })
</script>
</body>

</html>